package com.iceclean.daoImpl;

import com.iceclean.dao.ResourceDao;
import com.iceclean.po.CommentResource;
import com.iceclean.util.JdbcUtil;

import java.util.List;

/**
 * @author : Ice'Clean
 * @date : 2021-05-15
 */
public class ResourceDaoImpl implements ResourceDao {
    @Override
    public CommentResource findCommentResource(int resourceId) {
        List<CommentResource> commentResourceList = JdbcUtil.query("select * from t_resource where resource_id = ?", CommentResource.class, resourceId);
        return commentResourceList.size() == 0 ? null : commentResourceList.get(0);
    }

    @Override
    public List<CommentResource> findAllCommentResourceByIdentify(String resourceIdentify) {
        return JdbcUtil.query("select * from t_resource where resource_identify = ?", CommentResource.class, resourceIdentify);
    }

    @Override
    public List<CommentResource> findResourceByCommentId(int commentId) {
        return JdbcUtil.query("select * from t_resource where comment_id = ?", CommentResource.class, commentId);
    }

    @Override
    public int createCommentResource(CommentResource commentResource) {
        return JdbcUtil.insert("t_resource", commentResource);
    }

    @Override
    public boolean deleteCommentResource(int resourceId) {
        return JdbcUtil.delete("t_resource", "resource_id = " + resourceId);
    }

    @Override
    public boolean updateCommentResource(CommentResource commentResource) {
        return JdbcUtil.update("t_resource", "resource_id = " + commentResource.getResourceId(), commentResource);
    }
}
